package com.dense.kuiniu.bookborrow.business.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dense.kuiniu.bookborrow.R;
import com.dense.kuiniu.bookborrow.business.entity.BorrowBookInfo;
import com.dense.kuiniu.bookborrow.utils.RandomCoverUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * @author Administrator
 * @date 2020/8/13
 */
public class BookBorrowByUserAdapter extends BaseQuickAdapter<BorrowBookInfo, BaseViewHolder> {
    public BookBorrowByUserAdapter(int layoutResId, @Nullable List<BorrowBookInfo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, BorrowBookInfo bookBean) {

        ImageView cover = baseViewHolder.getView(R.id.iv_cover);

        Glide.with(getContext())
                .load(bookBean.getBookCover())
                .centerCrop()
                .error(RandomCoverUtils.getRandomCover())
                .placeholder(RandomCoverUtils.getRandomCover())
                .into(cover);
        baseViewHolder.setText(R.id.tv_author_value, bookBean.getBookauthor());
        baseViewHolder.setText(R.id.tv_bar_code_value, bookBean.getBarCode());
        baseViewHolder.setText(R.id.tv_name, String.format("《%s》", bookBean.getBookName()));
        baseViewHolder.setText(R.id.tv_borrow_time_value, bookBean.getBorrowDate());
        baseViewHolder.setText(R.id.tv_return_time_value, String.valueOf(bookBean.getBackDate()));
    }
}